<template>
  <div>
    <el-input :modelValue="userName" @update:modelValue="handleInput" />
    <button @click="handleSubmit">提交</button>
  </div>
</template>

<script setup>
import { defineProps, defineEmits, ref } from 'vue'
let props = defineProps({
  modelValue: {
    type: String
  }
})
// 接收父组件传递过来的参数，userName定义一个初始值
let userName = ref(props.modelValue)
const emits = defineEmits(['handleSubmit', 'update:modelValue'])

const handleInput = (val) => {
  console.log(val);
  userName.value = val
  emits('update:modelValue', val)
}
const handleSubmit = () => {
  emits('handleSubmit', userName)
}
</script>

<style lang="scss" scoped>
</style>